home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / System / PPCReleaseDEV / Examples / Msg4PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-21  |  2.6 KB  |  132 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/message.h>
  8. #include <powerup/ppclib/tasks.h>
  9. #include <powerup/gcclib/powerup_protos.h>
  10.  
  11. #define TEXT    "Text sent by PPC processor\n"
  12. #define    DEBUG    0
  13.  
  14. struct StartupData
  15. {
  16.     void    *MsgPort;
  17.     ULONG    MsgCount;
  18. };
  19.  
  20. BPTR    MyFile;
  21. void printf(char *String);
  22.  
  23. int    main(void)
  24. {
  25. struct TagItem        MyTags[10];
  26. struct StartupData    *StartupData;
  27. void            *ReplyPort;
  28. void            *M68kPort;
  29. void            *PPCMsg;
  30. void            *M68kMsg;
  31. void            *Body;
  32. ULONG            result;
  33. ULONG            MsgCount;
  34. ULONG            i;
  35.  
  36.   StartupData    =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
  37.   MsgCount    =    StartupData->MsgCount;
  38. #if DEBUG
  39.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  40.   {
  41. #endif
  42.     if (M68kPort=StartupData->MsgPort)
  43.     {
  44. #if DEBUG
  45.       printf("Allocating memory for message body\n");
  46. #endif
  47.       if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  48.       {
  49. #if DEBUG
  50.         printf("Creating reply port\n");
  51. #endif
  52.         MyTags[0].ti_Tag = TAG_DONE;
  53.         if (ReplyPort = PPCCreatePort(MyTags))
  54.         {
  55. #if DEBUG
  56.           printf("Creating message\n");
  57. #endif
  58.           if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  59.           {
  60. #if DEBUG
  61.             printf("Obtaining PPC port...");
  62. #endif
  63.             strcpy(Body, TEXT);
  64.  
  65.             for (i=0;i<MsgCount;i++)
  66.             {
  67.               PPCSendMessage(M68kPort,
  68.                              PPCMsg,
  69.                              Body,
  70.                              sizeof(TEXT),
  71.                              0x12345678);
  72.               PPCWaitPort(ReplyPort);
  73.               PPCGetMessage(ReplyPort);
  74.             }
  75.  
  76. #if DEBUG
  77.             printf("Deleting Message\n");
  78. #endif
  79.             PPCDeleteMessage(PPCMsg);
  80.           }
  81.           else
  82.           {
  83. #if DEBUG
  84.             printf("Could not create ppc msg\n");
  85. #endif
  86.           }
  87.  
  88. #if DEBUG
  89.           printf("Deleting reply port\n");
  90. #endif
  91.           while (PPCDeletePort(ReplyPort) == FALSE);
  92.         }
  93.         else
  94.         {
  95. #if DEBUG
  96.           printf("Could not create reply port\n");
  97. #endif
  98.         }
  99.  
  100. #if DEBUG
  101.         printf("Freeing message body memory\n");
  102. #endif
  103.         PPCFreeVec(Body);
  104.       }
  105.       else
  106.       {
  107. #if DEBUG
  108.         printf("Could not alloc mem for msg body\n");
  109. #endif
  110.       }
  111.  
  112.     }
  113.     else
  114.     {
  115. #if DEBUG
  116.       printf("Could not get a M68k msgport\n");
  117. #endif
  118.     }
  119.  
  120. #if DEBUG
  121.     printf("Closing output\n");
  122.     PPCClose(MyFile);
  123.   }
  124. #endif
  125. }
  126.  
  127. void printf(char *String)
  128. {
  129.   PPCWrite(MyFile, String, strlen(String));
  130. }
  131.  
  132.